import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '主页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '主页', icon: 'home01' }
    }]
  },

  {
    path: '/systemManager',
    component: Layout,
    redirect: '/example/systemManager',
    name: 'systemManager',
    meta: { title: '教务管理', icon: 'system01' },
    children: [
      {
        path: 'classManager',
        name: 'classManager',
        component: () => import('@/views/class/index'),
        meta: { title: '班级管理', icon: 'el-icon-s-grid' }
      },
      {
        path: 'courseManager',
        name: 'courseManager',
        component: () => import('@/views/course/index'),
        meta: { title: '课程管理', icon: 'el-icon-star-on' }
      },
      {
        path: 'studentManager',
        name: 'studentManager',
        component: () => import('@/views/student/index'),
        meta: { title: '学生管理', icon: 'user' }
      },
      {
        path: 'scoreManager',
        name: 'scoreManager',
        component: () => import('@/views/score/index'),
        meta: { title: '成绩管理', icon: 'el-icon-s-help' }
      },
    ]
  },

  {
    path: '/Nested',
    component: Layout,
    name: '友情链接',
    meta: {
      title: '友情链接',
      icon: 'link01'
    },
    children: [
      {
        path: 'https://cn.vuejs.org',
        component: Layout,
        meta: { title: 'Vue官网', icon: 'link' }
      },
      {
        path: 'https://echarts.apache.org/zh/index.html',
        component: Layout,
        meta: { title: 'Echarts官网', icon: 'link' }
      },
      {
        path: 'https://element.eleme.cn/#/zh-CN',
        component: Layout,
        meta: { title: 'Element', icon: 'link' }
      },
      {
        path: 'https://music.163.com/',
        component: Layout,
        meta: { title: '网易云音乐', icon: 'link' }
      },
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
